<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //数组排序

        //1. 翻转数组
        var arr = [1, 2, 3];
        arr.reverse();
        console.log(arr); // (3) [3, 2, 1]

        //2. 数组排序(冒泡排序)
        var arr1 = [3, 4, 7, 1];
        arr1.sort();
        console.log(arr1); //(4) [1, 3, 4, 7]

        // 但是有问题
        var arr2 = [1, 13, 4, 7, 77];
        arr2.sort();
        console.log(arr2); //(5) [1, 13, 4, 7, 77]
        //未能成功实现冒泡排序


        //改进
        var arr2 = [1, 13, 4, 7, 77];
        arr2.sort(function(a, b) {
            return a - b; //升序的顺序排列
        });
        console.log(arr2); //(5) [1, 4, 7, 13, 77]
    </script>
</head>

<body>

</body>

</html>